
//
//  NewsTableViewCell.m
//  SpiritWalk
//
//  Created by shange1999 on 16/3/11.
//  Copyright © 2016年 王鑫. All rights reserved.
//

#import "NewsTableViewCell.h"

@implementation NewsTableViewCell



-(void)layoutSubviews{
    [super layoutSubviews];
    [self.picurl sd_setImageWithURL:[NSURL URLWithString:self.receiveModel.picurl]];
    self.title.numberOfLines = 0;
    self.title.text = self.receiveModel.title;
    self.line.frame = CGRectMake(0, 0.5, WIDTH, 0.5);
    self.pubdate.text =[self compareCurrentTime:self.receiveModel.pubdate];
    self.seeCount.image =[UIImage imageNamed:@"yanjing"];
    self.click.text = [NSString stringWithFormat:@"%@",self.receiveModel.click];
    self.newsTypename.text = self.receiveModel.newsTypename;

}
#pragma 拼接时间
-(NSString*) compareCurrentTime:(NSString*)modelStr{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";    //格式
   NSDate *modelDate = [formatter dateFromString:modelStr];  //字符串
    NSTimeInterval  timeInterval = [modelDate timeIntervalSinceNow];
    timeInterval = -timeInterval;
    long temp = 0;
    NSString *result;
    if (timeInterval/60 < 60) {
        return [NSString stringWithFormat:@"刚刚"];
    }
    else if((temp = timeInterval/60) <60){
        result = [NSString   stringWithFormat:@"%ld分钟前",temp ];
    }
    else if((temp = temp/60) <24){
        return [NSString stringWithFormat:@"%ld小时前",temp];
    }
    else if((temp = temp/24) <30){
        return [NSString stringWithFormat:@"%ld天前",temp];
    }
    else if((temp = temp/30) <12){
        return [NSString stringWithFormat:@"%ld月前",temp];
    }
    else{
        temp = temp/12;
        return [NSString stringWithFormat:@"%ld年前",temp];
    }
    return  result;
}

- (void)awakeFromNib {
    // Initialization code
    self.line =[[UIView alloc]init];
    self.line.backgroundColor =[UIColor blackColor];
    [self.contentView addSubview:self.line];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
